<page-header [title]="l('Tenants')">
</page-header>

<!-- 全屏显示 -->
<!-- <full-content (fullscreenChange)="fullChange($event)"> -->
<!-- 表格部分 -->
<nz-card [nzBordered]="false">
  <!-- 检索表单 -->
  <form nz-form [nzLayout]="'vertical'" (ngSubmit)="refresh()">
    <nz-row nzGutter="8">
      <nz-col nzSm="12">
        <nz-form-item>
          <nz-form-label>
            {{l('TenantNameOrTenancyCode')}}
          </nz-form-label>
          <nz-form-control>
            <nz-input-group nzSearch [nzSuffix]="suffixButton">
              <input type="text" nz-input [(ngModel)]="filterText" (keyup.enter)="refresh()" name="filterText"
                [placeholder]="l('SearchWithThreeDot')">
              <ng-template #suffixButton>
                <button nz-button nzType="primary" nzSearch type="submit">
                  <i class="anticon anticon-search"></i>
                  <!-- {{l('Search')}} -->
                </button>
              </ng-template>
            </nz-input-group>
          </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col nzSm="12">
        <nz-form-item>
          <nz-form-label>
            {{l('Edition')}}
          </nz-form-label>
          <nz-form-control>
            <edition-combo [placeholder]="l('PleaseSelect')" (selectedEditionChange)="selectedEditionChange($event)"></edition-combo>
            <!-- <edition-select [(selectedEdition)]="filters.selectedEditionId" (selectedEditionChange)="refresh()"></edition-select> -->
          </nz-form-control>
        </nz-form-item>
      </nz-col>
    </nz-row>

    <nz-row nzGutter="8" *ngIf="advancedFiltersVisible">
      <nz-col nzSm="12">
        <nz-form-item>
          <nz-form-label>
            {{l('SubscriptionEndDateUtc')}}
          </nz-form-label>
          <nz-form-control>
            <nz-range-picker name="SubscriptionEndDateRange" [(ngModel)]="subscribableDateRange" [nzPlaceHolder]="[l('StartDateTime'),l('EndDateTime')]"
              (ngModelChange)="refresh()" style="width:100%;"></nz-range-picker>
          </nz-form-control>
        </nz-form-item>
      </nz-col>
      <nz-col nzSm="12">
        <nz-form-item>
          <nz-form-label>
            {{l('CreationTime')}}
          </nz-form-label>
          <nz-form-control>
            <nz-range-picker name="CreationDateRange" [(ngModel)]="createDateRange" [nzPlaceHolder]="[l('StartDateTime'),l('EndDateTime')]"
              (ngModelChange)="refresh()" style="width:100%;"></nz-range-picker>
          </nz-form-control>
        </nz-form-item>
      </nz-col>
    </nz-row>

  </form>
  <!-- 操作部分 -->
  <nz-row nzGutter="8">
    <nz-col nzMd="20" nzSm="12" class="btn-gutter">
      <button nz-button [nzType]="'primary'" *ngIf="isGranted('Pages.Tenants.Create')" (click)="create()">
        <i class="anticon anticon-plus"></i>
        <span>
          {{l("CreateNewTenant")}}
        </span>
      </button>
      <button nz-button [nzType]="'danger'" *ngIf="isGranted('Pages.Tenants.Delete')" (click)="batchDelete()">
        <i class="anticon anticon-delete"></i>
        <span>
          {{l("BatchDelete")}}
        </span>
      </button>
    </nz-col>
    <nz-col nzMd="4" nzSm="12" class="text-right">
      <a (click)="advancedFiltersVisible=!advancedFiltersVisible">
        {{advancedFiltersVisible ? l('HideAdvancedFilters') : l('ShowAdvancedFilters')}}
        <i class="anticon" [class.anticon-down]="!advancedFiltersVisible" [class.anticon-up]="advancedFiltersVisible"></i>
      </a>


    </nz-col>
  </nz-row>
  <!-- 数据部分 -->
  <div class="my-md">
    <nz-alert [nzType]="'info'" [nzShowIcon]="true" [nzMessage]="message">
      <ng-template #message>
        <span [innerHTML]="l('GridSelectedXItemsTips',selectedDataItems.length)"></span>
        <a (click)="restCheckStatus(dataList)" class="ml-md">
          {{l('ClearEmpty')}}
        </a>
        <nz-divider nzType="vertical"></nz-divider>
        <a (click)="forceRefresh()">
          {{l('Refresh')}}
        </a>
      </ng-template>
    </nz-alert>
  </div>
  <nz-row class="my-md">
    <nz-table #nzDataTable [nzFrontPagination]="false" [nzShowQuickJumper]="true" [nzShowSizeChanger]="true" [nzData]="dataList"
      [nzTotal]="totalItems" [nzLoading]="isTableLoading" [(nzPageIndex)]="pageNumber" [(nzPageSize)]="pageSize"
      (nzPageIndexChange)="refresh()" (nzPageSizeChange)="refresh()" [nzNoResult]="noDataTemplate" [nzShowTotal]="showTotalTemplate">
      <!-- 暂无数据 -->
      <ng-template #noDataTemplate>
        <no-data></no-data>
      </ng-template>
      <!-- 分页信息显示 当前 1 页/共 3 页，共 5 条/显示 1-2 条 -->
      <ng-template #showTotalTemplate let-total let-range="range">
        {{l('GridFooterDisplayText',pageNumber,totalPages,total,range[0],range[1])}}
      </ng-template>
      <!-- 表头 -->
      <thead (nzSortChange)="gridSort($event)">
        <tr>
          <th nzShowCheckbox [(nzChecked)]="allChecked" [nzDisabled]="allCheckboxDisabled" [nzIndeterminate]="checkboxIndeterminate"
            (nzCheckedChange)="checkAll($event)"></th>

          <th nzShowSort nzSortKey="tenancyName">
            <span>{{l('TenancyCodeName')}}</span>
          </th>
          <th nzShowSort nzSortKey="name">
            <span>{{l('Name')}}</span>
          </th>
          <th nzShowSort nzSortKey="editionDisplayName">
            <span>{{l('Edition')}}</span>
          </th>
          <th nzShowSort nzSortKey="subscriptionEndUtc" class="text-center">
            <span>{{l('SubscriptionEndUtc')}}</span>
          </th>
          <th nzShowSort nzSortKey="isActive" class="text-center">
            <span>{{l('Active')}}</span>
          </th>
          <th nzShowSort nzSortKey="creationTime" class="text-center">
            <span>{{l('CreationTime')}}</span>
          </th>
          <th nzWidth="240px" class="text-center">
            <span>{{l('Actions')}}</span>
          </th>
        </tr>
      </thead>
      <!-- 表格内容 -->
      <tbody>
        <tr *ngFor="let item of nzDataTable.data">
          <td nzShowCheckbox [(nzChecked)]="item.checked" (nzCheckedChange)="refreshCheckStatus(this.dataList)"></td>

          <td>
            <span *ngIf="item.connectionString" nz-tooltip [nzTitle]="l('HasOwnDatabase')">
              <i class="anticon anticon-database"></i>
            </span>
            {{item.tenancyName}}
          </td>
          <td>
            {{item.name}}
          </td>
          <td>
            {{item.editionDisplayName}}
          </td>
          <td class="text-center">
            {{item.subscriptionEndUtc?(item.subscriptionEndUtc|_date : 'YYYY-MM-DD'):'—'}}
          </td>
          <td class="text-center" [innerHTML]="item.isActive | yn">
          </td>
          <td class="text-center">
            {{item.creationTime|_date: 'YYYY-MM-DD'}}
          </td>
          <td class="text-center">
            <!-- 编辑 -->
            <ng-container *ngIf="isGranted('Pages.Tenants.Edit')">
              <a (click)="edit(item.id)">
                <i class="anticon anticon-edit mr-sm"></i>
                <span>{{l('Edit')}}</span>
              </a>
              <nz-divider nzType="vertical"></nz-divider>
            </ng-container>
            <!-- 删除 -->
            <ng-container *ngIf="isGranted('Pages.Tenants.Delete')">
              <nz-popconfirm [nzTitle]="l('ConfirmDeleteWarningMessage')" (nzOnConfirm)="delete(item)" [nzOkText]="l('Ok')"
                [nzCancelText]="l('Cancel')">
                <a nz-popconfirm>
                  <i class="anticon anticon-delete mr-sm"></i>
                  <span>{{l('Delete')}}</span>
                </a>
              </nz-popconfirm>
              <nz-divider nzType="vertical"></nz-divider>
            </ng-container>
            <!-- 更多 -->
            <ng-container>
              <nz-dropdown>
                <a nz-dropdown>
                  <i class="icon-options-vertical mr-sm"></i>
                  <span>{{l('More')}}</span>
                  <i class="anticon anticon-down"></i>
                </a>
                <ul nz-menu>
                  <li nz-menu-item *ngIf="isGranted('Pages.Tenants.Impersonation')" (click)="tenantImpersonateLogin(item)">
                    <a>
                      <i class="anticon anticon-login mr-sm"></i>
                      <span>{{l('LoginAsThisTenant')}}</span>
                    </a>
                  </li>
                  <li nz-menu-item *ngIf="item.isActive&&isGranted('Pages.Tenants.ChangeFeatures')" (click)="changeTenantFeatures(item)">
                    <a>
                      <i class="anticon anticon-codepen mr-sm"></i>
                      <span>{{l('Features')}}</span>
                    </a>
                  </li>
                  <li nz-menu-item (click)="unlockTenantAdminUser(item)">
                    <a>
                      <i class="anticon anticon-unlock mr-sm"></i>
                      <span>{{l('Unlock')}}</span>
                    </a>
                  </li>
                </ul>
              </nz-dropdown>
            </ng-container>
          </td>
        </tr>
      </tbody>
    </nz-table>
  </nz-row>

</nz-card>
<!-- </full-content> -->
